package com.turnengine.client.local.unit.command;

import org.apache.commons.lang.builder.CompareToBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * The Set Unit Score.
 */
public class SetUnitScore implements ISetUnitScore {

	/** The command id. */
	public static final short COMMAND_ID = 1911;

	/** The login id. */
	private long loginId;
	/** The instance id. */
	private int instanceId;
	/** The name. */
	private String name;
	/** The group name. */
	private String groupName;
	/** The score. */
	private long score;

	/**
	 * Creates a new Set Unit Score.
	 */
	public SetUnitScore() {
	}

	/**
	 * Creates a new Set Unit Score.
	 * @param loginId the login id
	 * @param instanceId the instance id
	 * @param name the name
	 * @param groupName the group name
	 * @param score the score
	 */
	public SetUnitScore(long loginId, int instanceId, String name, String groupName, long score) {
		setLoginId(loginId);
		setInstanceId(instanceId);
		setName(name);
		setGroupName(groupName);
		setScore(score);
	}

	/**
	 * Creates a new Set Unit Score.
	 * @param iSetUnitScore the i set unit score
	 */
	public SetUnitScore(ISetUnitScore iSetUnitScore) {
		setLoginId(iSetUnitScore.getLoginId());
		setInstanceId(iSetUnitScore.getInstanceId());
		setName(iSetUnitScore.getName());
		setGroupName(iSetUnitScore.getGroupName());
		setScore(iSetUnitScore.getScore());
	}

	/**
	 * Returns the login id.
	 * @return the login id.
	 */
	public long getLoginId() {
		return loginId;
	}

	/**
	 * Returns the instance id.
	 * @return the instance id.
	 */
	public int getInstanceId() {
		return instanceId;
	}

	/**
	 * Returns the name.
	 * @return the name.
	 */
	public String getName() {
		return name;
	}

	/**
	 * Returns the group name.
	 * @return the group name.
	 */
	public String getGroupName() {
		return groupName;
	}

	/**
	 * Returns the score.
	 * @return the score.
	 */
	public long getScore() {
		return score;
	}

	/**
	 * Sets the login id.
	 * @param loginId the login id to set.
	 */
	public void setLoginId(long loginId) {
		this.loginId = loginId;
	}

	/**
	 * Sets the instance id.
	 * @param instanceId the instance id to set.
	 */
	public void setInstanceId(int instanceId) {
		this.instanceId = instanceId;
	}

	/**
	 * Sets the name.
	 * @param name the name to set.
	 */
	public void setName(String name) {
		if (name == null) {
			throw new NullPointerException("name");
		}
		this.name = name;
	}

	/**
	 * Sets the group name.
	 * @param groupName the group name to set.
	 */
	public void setGroupName(String groupName) {
		if (groupName == null) {
			throw new NullPointerException("groupName");
		}
		this.groupName = groupName;
	}

	/**
	 * Sets the score.
	 * @param score the score to set.
	 */
	public void setScore(long score) {
		this.score = score;
	}

	/**
	 * Returns the hash code.
	 * @return the hash code.
	 */
	@Override
	public int hashCode() {
		HashCodeBuilder hash = new HashCodeBuilder(1223, 37);
		hash.append(loginId);
		hash.append(instanceId);
		hash.append(name);
		hash.append(groupName);
		hash.append(score);
		return hash.toHashCode();
	}

	/**
	 * Returns true if this is equal to the given object.
	 * @param object the object to compare.
	 * @return true if this is equal to the given object.
	 */
	@Override
	public boolean equals(Object object) {
		if (object == this) {
			return true;
		}
		if (object instanceof SetUnitScore) {
			SetUnitScore compare = (SetUnitScore) object;
			EqualsBuilder equals = new EqualsBuilder();
			equals.append(this.loginId, compare.loginId);
			equals.append(this.instanceId, compare.instanceId);
			equals.append(this.name, compare.name);
			equals.append(this.groupName, compare.groupName);
			equals.append(this.score, compare.score);
			return equals.isEquals();
		}
		return false;
	}

	/**
	 * Compare this to the given object.
	 * @param compare the object to compare to.
	 * @return the result of the comparison.
	 */
	@Override
	public int compareTo(ISetUnitScore compare) {
		CompareToBuilder builder = new CompareToBuilder();
		builder.append(this.loginId, compare.getLoginId());
		builder.append(this.instanceId, compare.getInstanceId());
		builder.append(this.name, compare.getName());
		builder.append(this.groupName, compare.getGroupName());
		builder.append(this.score, compare.getScore());
		return builder.toComparison();
	}

	/**
	 * Returns this as a string.
	 * @return this as a string.
	 */
	@Override
	public String toString() {
		ToStringBuilder string = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
		string.append("loginId", loginId);
		string.append("instanceId", instanceId);
		if (name != null) {
			string.append("name", name);
		}
		if (groupName != null) {
			string.append("groupName", groupName);
		}
		string.append("score", score);
		return string.toString();
	}

	public short getCommandId() {
		return COMMAND_ID;
	}
}
